<?php 

class Event_BannerForm extends Crud_Event_Handler 
{
	protected $_type = 'form';
		
	/**
	 * Run handler with options array.
	 * 
	 * @param Crud_Form $form
	 * @return void
	 */
	public function run($form)
	{
		$element = $form->getElement('banner2place');
		$r = $form->getRow();
    
    if(count($r))
    {
    
			$db = Db::getConnection ();
			/*$sql = '
			select *
			from banner2place
			inner join banner_place on banner_place.id=banner2place.place_id
			where banner_place.format_id = '.$r->getFormat().'
			group by place_id
			';*/
			
			$sql = '
			select *
			from banner_place
			#left join banner2place on banner_place.id=banner2place.place_id
			where banner_place.format_id = '.$r->getFormat().'
			#group by place_id
			';
			
			//d($sql);
			$rowset = $db->fetchAll ( $sql );
			
			$values = array();
			foreach ($rowset as $row) {
				$values[ $row["id"] ] = $row["name"];
			}
			
			$element->clearMultiOptions();
			//$element->addMultiOption(null);
			$element->addMultiOptions($values);
		}
	}
}